package com.stu_ques.users.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.stu_ques.users.dao.ILevelDao;
import com.stu_ques.users.dao.IStudentDao;
import com.stu_ques.users.pojo.Level;
import com.stu_ques.users.pojo.Student;
import com.stu_ques.users.service.IUsersService;

public class UsersServiceImpl implements IUsersService
{
	/* 调用学生的Dao */
	private IStudentDao studentDao;
	private ILevelDao levelDao;

	/**
	 * 学生表 Service 添加一条学生信息
	 */
	@Override
	public int saveOneStudentService(Student student)
	{
		return this.studentDao.saveOneDao(student);
	}

	/**
	 * 学生表 Service 更新一条学生信息
	 */
	@Override
	public void updateOneStudentService(Student student)
	{
		this.studentDao.updateOneDao(student);
	}

	/**
	 * 学生表 Service 删除一条学生信息
	 */
	@Override
	public void deleteOneStudentService(Student student)
	{
		this.studentDao.deleteOneDao(student);
	}

	/**
	 * 学生表 Service 查询一条学生信息
	 */
	@Override
	public Student selectStudentService(Map<String, Object> condMap)
	{
		return this.studentDao.selectOneDao(condMap);
	}

	/**
	 * 学生表 Service 查询所有学生信息
	 */
	@Override
	public List<Student> selectListStudentService()
	{
		List<Student> studentList= this.studentDao.selectListDao();
		Map<String , Object> condMap = new HashMap<String, Object>();
		for (Student student : studentList)
		{
			/*	清空容器	*/
			condMap.clear();
			condMap.put("id", student.getLevelId());
			Level level = this.selectLevelService(condMap);
			student.setLevel(level);
		}
		return studentList;
	}

	/**
	 * 学生表 Service 学生标题
	 */
	@Override
	public String printTitleStudentService()
	{
		String str = "id\t等级\t名字\t性别\t生日\t\t住址\t毕业学校\t分数\t总次数\t正确次数\t错误次数\t正确率\t创建时间\t\t\t结束时间";
		return str;
	}

	/**
	 * 等级表 Service 添加一条等级信息
	 */
	@Override
	public int saveOneLevelService(Level level)
	{
		return this.levelDao.saveOneDao(level);
	}

	/**
	 * 等级表 Service 更新一条等级信息
	 */
	@Override
	public void updateOneLevelService(Level level)
	{
		this.levelDao.updateOneDao(level);
	}

	/**
	 * 等级表 Service 删除一条等级信息
	 */
	@Override
	public void deleteOneLevelService(Level level)
	{
		this.levelDao.deleteOneDao(level);
	}

	/**
	 * 等级表 Service 查询一条等级信息
	 */
	@Override
	public Level selectLevelService(Map<String, Object> condMap)
	{
		return this.levelDao.selectOneDao(condMap);
	}

	/**
	 * 等级表 Service 查询所有等级信息
	 */
	@Override
	public List<Level> selectListLevelService()
	{
		return this.levelDao.selectListDao();
	}

	/**
	 * 等级表 Service 打印等级表 标题
	 */
	@Override
	public String printTitleLevelService()
	{
		String str = "id\t名字\t起始分数\t结束分数\t创建时间\t\t\t结束时间";
		return str;
	}

	@Override
	public int selectStudetMaxIdService()
	{
		return this.studentDao.selectMaxIdDao();
	}

	public void setStudentDao(IStudentDao studentDao)
	{
		this.studentDao = studentDao;
	}

	public void setLevelDao(ILevelDao levelDao)
	{
		this.levelDao = levelDao;
	}

}
